//
// Created by wangxiyue on 2019/9/20.
//
#include <stdio.h>

void print(int *a, int length) {

    for (int i = 0; i < length; i++) {
        printf("%d  ", a[i]);
    }
    printf("\n");
}

int *bubble_sort(int *a, int length) {

    for (int i = 0; i < length; i++) {
        int flag = 0;
        for (int j = 1; j < length - i; j++) {
            if (a[j - 1] > a[j]) {
                int temp = a[j - 1];
                a[j - 1] = a[j];
                a[j] = temp;
                flag = 1;
            }
        }
        if (!flag) {
            break;
        }
        print(a, length);
    }
    return a;
}


int main() {

    int a[] = {5, 0, 1, 2, 3, 4};
    bubble_sort(a, sizeof(a) / sizeof(int));
}